﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Text.RegularExpressions;
using Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ChBusiness.Struct;

namespace ChBusiness.Wsbs
{
    /// <summary>
    /// XT_PROCESS操作类
    /// </summary>
    public class XtProcess
    {
        /// <summary>
        /// 根据流程名获取一个流程中的所有表格
        /// </summary>
        /// <param name="strName">流程名称</param>
        /// <returns></returns>
        public DataTable GetProcess(string strName)
        {
            Database dbTemp = BasicOperate.CreateNetOfficeDataBase();
            string strSql = string.Format(@"select a.TABLEANOTHERNAME, a.FID, a.tablename, a.flowname from XT_PROCESS a, xt_workflow_define b
                                             where a.flowid = b.id
                                               and b.ispub = '1'
                                               and b.isdelete = '0'
                                               and b.flowname like '%{0}%'
                                             ORDER BY a.orderdield", strName);


//            string strSql = string.Format(@"select a.TABLEANOTHERNAME,(select c.fid
//                  from st_form c
//                 where c.fname = (select fname from st_form where fid = a.fid) and c.rot=0) fid,
//                 a.tablename, a.flowname from XT_PROCESS a, xt_workflow_define b
//                 where a.flowid = b.id
//                   and b.ispub = '1'
//                   and b.isdelete = '0'
//                   and b.flowname like '%{0}%'
//                 ORDER BY a.orderdield", strName);

            return dbTemp.ExecuteDataSet(CommandType.Text, strSql).Tables[0];
        }

        /// <summary>
        /// 获取表单初始设定
        /// </summary>
        /// <param name="strFlowName">流程名称</param>
        /// <param name="strOtherName">表单别名</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20091120-->
        public DataTable GetFlowDefault(string strFlowName,string strOtherName)
        {
            Database dbTemp = BasicOperate.CreateNetOfficeDataBase();
            string strSql = string.Format(@" select id,can_sync,sync_type,flowname,flowid,source_tab_name,source_tabcol_name,source_tabcol_comment,target_tab_name,target_tabcol_name,target_tabcol_comment,logic_sql,flowothername 
                            from xt_form_default where 1=1 ");
            if(!string.IsNullOrEmpty(strFlowName))
                strSql += string.Format(" and flowname='{0}'", strFlowName);
            if (!string.IsNullOrEmpty(strOtherName))
                strSql += string.Format(" and flowothername='{0}'", strOtherName);

            return dbTemp.ExecuteDataSet(CommandType.Text, strSql).Tables[0];
        }

        /// <summary>
        /// 获取初始化设定值
        /// </summary>
        /// <param name="strSql">设定SQL</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20091120-->
        public DataTable GetDefaultValue(string strSql)
        {
            Database dbTemp = BasicOperate.CreateNetOfficeDataBase();
            return dbTemp.ExecuteDataSet(CommandType.Text, strSql).Tables[0];
        }
    }
}
